package com.lqian.demo01;

import com.lqian.utils.SleepHelper;

/**
 * interrupt() 和 isInterrupted
 * 设置标志位 + 查询标志位
 */
public class Interrupt_and_isInterrupted {
    public static void main(String[] args) {
        Thread t = new Thread(() -> {
            for (;;) {
                // check the flag
                if (Thread.currentThread().isInterrupted()) {
                    System.out.println("Thread is interrupted！");
                    System.out.println(Thread.currentThread().isInterrupted());
                    break;
                }

            }
        });

        t.start();
        SleepHelper.sleepSeconds(2);
        // Just to set the interrupt flag
        t.interrupt();  // >>>  flag = true

    }

}
